package com.shangxian.giveithome.utils;


import java.io.UnsupportedEncodingException;
import java.util.Base64;

public class Base64Utils {

    final static Base64.Decoder decoder = Base64.getDecoder();

    final static Base64.Encoder encoder = Base64.getEncoder();

    // 编码
    public static String encodeToString(String content) {
        return encodeToString(content.getBytes());
    }

    // 编码
    public static String encodeToString(byte[] bytes) {
        return encoder.encodeToString(bytes);
    }


    // 解码
    public static String decode(String encode) {
        try {
            return new String(decoder.decode(encode), "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            return null;
        }
    }

}
